<template>
  <div>
    <el-form
      ref="dicTypeForm"
      :rules="rules"
      :model="dicTypInfo"
      label-position="right"
      label-width="120px"
    >
      <el-row>
        <el-col :span="12">
          <el-form-item label="🍁标题">
            <el-input v-model="dicTypInfo.title"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="15">
          <el-form-item label="🍁用途描述">
            <el-input type="textarea" v-model="dicTypInfo.yongtu"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="15">
          <el-form-item label="备注">
            <el-input type="textarea" v-model="dicTypInfo.beizhu"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <!-- <el-row>
          <el-col :span="12">
            <el-form-item label="🍁输入领用物品">
              <el-input v-model="dicTypInfo.m_name"></el-input>
            </el-form-item>
          </el-col>
        </el-row> -->
    </el-form>


    <el-card class="box-card" style="width:800px">
       <el-table
      ref="delalldec"
      :data="list"
      style="width: 100%"
      v-loading="listLoading"
      border
      fit
      highlight-current-row
    >
      <el-table-column prop="m_name" label="货物名称"> </el-table-column>
      <el-table-column prop="m_kind" label="类型"> </el-table-column>
      <el-table-column prop="m_texture" label="材质"> </el-table-column>
      <el-table-column prop="m_specification" label="规格"> </el-table-column>
      <el-table-column prop="m_num" label="仓库数量"> </el-table-column>
      <el-table-column prop="m_price" label="领用数量"> </el-table-column>
      <el-table-column fixed="right" label="操作">
        <template slot-scope="scope">
          <el-button @click="handledel(scope.row.id)" type="text" size="small"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    </el-card>

   

    <div slot="footer" class="dialog-footer">
      <!-- dialogStatus === '1' 是添加 就执行添加的方法  是修改  就执行修改的方法-->
      <el-button type="primary" @click="addDictType()"> 保存 </el-button>
      <el-button> 取消 </el-button>
    </div>
  </div>
</template>

  <script>
import { dttCreateds, dttGetAll,del } from "@/api/system_base/stock_manager";

export default {
  data() {
    return {
      list: null,
      listLoading: true,
      dialogStatus: "1", // 等于1 表示是添加操作   不等于1 表示修改操作
      dicTypInfo: {},
    };
  },
  created() {
    this.searchPageList();
    this.resetDicinfo();
  },
  methods: {
    searchPageList() {
      // 搜索方法
      this.listLoading = true; // 显示加载效果

      dttGetAll(this.search).then((response) => {
        // 调用分页接口
        this.list = response.result.items; // 将查询结果赋值给list
        this.listLoading = false; // 隐藏加载效果
      });
    },
    addDictType() {
      if(this.dicTypInfo.title=="") 
       {
         this.$message("标题不能为空");
         return;
       }
       if(this.dicTypInfo.yongtu=="") 
       {
         this.$message("用途描述不能为空");
         return;
       }
      //添加方法
      this.$refs["dicTypeForm"].validate((valid) => {
        if (valid) {
          dttCreateds(this.dicTypInfo).then((response) => {
            this.$router.push("/lingyong");
            this.$notify({
              title: "添加成功",
              message: "添加物资信息成功",
              type: "success",
              duration: 2000,
            });
          });
        }
      });
    },
    resetDicinfo() {
      // 初始化用户对象
      this.dicTypInfo = {
        title: "",
        yongtu: "",
        beizhu: "",
      };
    },
    handledel(id) {
      if (confirm("确认删除数据吗？")) {
        del(id).then((res) => {
          this.$message.success("删除成功");
          this.searchPageList();
        });
      }
    },
  },
};
</script>

<style >
.search_input {
  width: 200px;
}
</style>